package com.renzhebiao.lkang.master;

import java.io.Serializable;

public class ExecuteResult<T> implements Serializable {

    /*
     * 提示信息
     */
    private String  message;
    /*
     * 状态码
     */
    private int     code;
    /*
     * 返回数据
     */
    private T       value;
    /*
     * 执行结果
     */
    private boolean success;

    public static <T> ExecuteResult<T> ok() {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.code = 0;
        result.success = true;
        return result;
    }

    public static <T> ExecuteResult<T> ok(T value) {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.value = value;
        result.code = 0;
        result.success = true;
        return result;
    }

    public static <T> ExecuteResult<T> ok(String message, T value) {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.message = message;
        result.value = value;
        result.code = 0;
        result.success = true;
        return result;
    }

    public static <T> ExecuteResult<T> fail() {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.code = -1;
        result.success = false;
        return result;
    }

    public static <T> ExecuteResult<T> fail(String message) {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.message = message;
        result.code = -1;
        result.success = false;
        return result;
    }

    public static <T> ExecuteResult<T> fail(int errorCode) {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.code = errorCode;
        result.success = false;
        return result;
    }

    public static <T> ExecuteResult<T> fail(int errorCode, String message) {
        ExecuteResult<T> result = new ExecuteResult<T>();
        result.message = message;
        result.code = errorCode;
        result.success = false;

        return result;
    }

    @Override
    public String toString() {
        return "ExecuteResult [message=" + message + ", code=" + code + ", value=" + value + ", success=" + success
               + "]";
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

}
